'use strict'

const {DataTypes, Model, Op } = require('../../../azeroth').sequelize;
class Doff_1 extends Model {}

const initDoffData_1 = (sequelize_aim) => {
  Doff_1.init(
    {
        uid: {
            autoIncrement: true,
            type: DataTypes.INTEGER,
            allowNull: false,
            primaryKey: true
        },
        jobId: {
            type: DataTypes.INTEGER,
            allowNull: false,
            defaultValue: 0,
            primaryKey: true
        },
        doffNum: {
            type: DataTypes.INTEGER,
            allowNull: true
        },
        startPosition: {
            type: DataTypes.DECIMAL(16,1),
            allowNull: true
        },
        lastPosition: {
            type: DataTypes.DECIMAL(16,1),
            allowNull: true
        },
        viewWidth: {
            type: DataTypes.INTEGER,
            allowNull: true
        },
        status: {
            type: DataTypes.INTEGER,
            allowNull: true
        },
        flawCount: {
            type: DataTypes.INTEGER,
            allowNull: true
        },
        startTime: {
            type: DataTypes.BIGINT,
            allowNull: true
        },
        finishTime: {
            type: DataTypes.BIGINT,
            allowNull: true
        },
        laneInfo: {
            type: DataTypes.TEXT,
            allowNull: true
        },
        comment: {
            type: DataTypes.STRING(1024),
            allowNull: true
        },
        detectFileName: {
            type: DataTypes.STRING(128),
            allowNull: true
        },
        detectParam: {
            type: DataTypes.TEXT,
            allowNull: true
        },
        exField: {
            type: DataTypes.STRING(256),
            allowNull: true
        },
        exConfig1: {
            type: DataTypes.TEXT,
            allowNull: true
        },
        exConfig2: {
            type: DataTypes.TEXT,
            allowNull: true
        }
    },
    {
      freezeTableName: true,
      sequelize: sequelize_aim,
      modelName: 'doff',
      timestamps: false
    }
  )
}

Doff_1.upload = async (data) => {
  let res = await Doff_1.bulkCreate([data], {
    updateOnDuplicate: ['uid', 'jobId', 'doffNum', 'startPosition', 'lastPosition', 'flawCount', 'startTime', 'finshtTime', 'comment', 'detectParam', 'exConfig1']
  });
  return res;
}

module.exports = {
  Doff_1,
  initDoffData_1
};